using System;
using System.Collections.Generic;
using System.Linq;
using System.Diagnostics;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;

using WindowsGameInput;



namespace WindowsGame
{
    public class Game1 : Microsoft.Xna.Framework.Game
    {
        GraphicsDeviceManager graphics;

		IGameOptionsService gameOptionsService;



        public Game1()
        {
            graphics = new GraphicsDeviceManager(this);
            graphics.PreferredBackBufferWidth = 1024;
            graphics.PreferredBackBufferHeight = 768;
            graphics.SynchronizeWithVerticalRetrace = false;
			graphics.IsFullScreen = false;
            Content.RootDirectory = "Content";

			IsMouseVisible = true;
            IsFixedTimeStep = false;
        }



		private void OnOptionsChanged()
		{
			graphics.PreferredBackBufferWidth = gameOptionsService.Settings.resWidth;
			graphics.PreferredBackBufferHeight = gameOptionsService.Settings.resHeigth;
			graphics.SynchronizeWithVerticalRetrace = gameOptionsService.Settings.vSync;
			graphics.IsFullScreen = gameOptionsService.Settings.fullscreen;
			graphics.ApplyChanges();
		}



        protected override void Initialize()
        {
			WindowsGameInput.SoundsHandler.Init(this);

            this.Components.Add(new ResourcesHandler(this));
            this.Components.Add(new InputHandler(this));
			this.Components.Add(new MenuHandler(this));

			gameOptionsService = Services.GetService(typeof(IGameOptionsService)) as IGameOptionsService;
			gameOptionsService.OptionsChanges += OnOptionsChanged;

            base.Initialize();
        }



        protected override void Dispose(bool disposing)
        {
            base.Dispose(disposing);
        }



        protected override void LoadContent()
        {
            // Load any non ContentManager content here
        }



        protected override void UnloadContent()
        {
            // Unload any non ContentManager content here
        }



        protected override void Update(GameTime gameTime)
        {
            base.Update(gameTime);
        }



        protected override void Draw(GameTime gameTime)
        {
            base.Draw(gameTime);
        }
    }
}
